<template>
  <div class="admig_List">
    <el-table :data="adminList" border style="width: 100%">
      <el-table-column prop="uid" label="用户编号" width="180">
      </el-table-column>
      <el-table-column prop="username" label="用户名称" width="180">
      </el-table-column>
      <el-table-column prop="" label="所属角色">
        <template slot-scope="item">
          <div>
            {{ item.row.rolename }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="item">
          <div>
            {{ item.row.status == 1 ? "启用" : "禁止" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="item">
          <div>
            <el-button
              type="primary"
              size="mini"
              @click="getDialog(item.row.uid)"
              >编辑</el-button
            >
            <el-button @click="delAdmin(item.row.uid)" type="danger" size="mini"
              >删除</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- total      总条数
        page-size	每页显示条目个数，支持 .sync 修饰符
        layout	组件布局，子组件名用逗号分隔
    -->
    <el-pagination
      background
      :page-size="pageSize"
      layout="prev, pager, next"
      :total="count"
      @current-change="changePage"
    >
    </el-pagination>
  </div>
</template>
<script>
import { userdelete } from "../../request/api";
import { mapGetters, mapActions } from "vuex";
export default {
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      adminList: "admin/getAdmin",
      pageSize: "admin/getSize",
      count: "admin/getCount",
    }),
  },
  mounted() {
    this.getAdmigAction();
    this.getCountAction();
  },
  methods: {
    ...mapActions({
      getAdmigAction: "admin/getAdmigAction",
      getCountAction: "admin/getCountAction",
      changePageAction:"admin/changePageAction",
    }),
    //表格内的编辑按钮
    getDialog(uid) {
      this.$emit("edit", uid);
    },
    //删除按钮
    delAdmin(uid) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          userdelete({ uid }).then((res) => {
            if (res.code == 200) {
              this.$message.success(res.msg);
              //删除成功重新调用列表
              this.getAdmigAction();
              //重新调用总数接口
              this.getCountAction()
              //
            } else {
              this.$message.error(res.msg);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //封装一个切换页面的事件
    changePage(e){
        //e 参数 点击页码返回对应的页码数
        this.changePageAction(e)
    }
  },
};
</script>
<style scoped>
</style>